package com.me.study.javaCore.io;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @author ME
 * @date 2019/12/31
 */
public class CSVParse {

    public static void main(String[] args) {
        try {
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(new FileInputStream("C:/Users/ME/Desktop/all_all-cm_lte_enb.csv"),
                    "GBK"));
            int nullCount = 0;
            int count = 0;
            // 第一行信息，为标题信息，不用,如果需要，注释掉
            String line = reader.readLine();
            String[] item = line.split("\\|", -1);
            System.out.println(Arrays.toString(item));
            int lineNum = 1;
            int index = ArrayUtils.indexOf(item, "RRU_MODEL");
            int codeindex = ArrayUtils.indexOf(item, "RRU_CODE");
            int enbindex = ArrayUtils.indexOf(item, "ENB_ID");
            Set<String> set = new HashSet<>();

            while ((line = reader.readLine()) != null) {
                //CSV格式文件为逗号分隔符文件，这里根据逗号切分
                item = line.split("\\|", -1);

                if (codeindex != -1) {
                    String code = item[codeindex];
                    if (code.equals("OMC_6301.ENB_810024.RRU_0-63-0")) {
                        System.out.println(Arrays.toString(item));
                    }
                }
                if (index != -1) {
                    String model = item[index];
                    // System.out.println(Arrays.toString(item));
                    if (StringUtils.isBlank(model) || model.equals("null")) {
                        nullCount++;
                    }
                }
                if (enbindex != -1) {
                    String id = item[enbindex];
                    set.add(id);
                    if (id.equals("766306")) {
                        System.out.println(Arrays.toString(item));
                    }
                }
                lineNum++;
            }

            System.out.println("nullCount: " + nullCount);
            System.out.println(set.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
